'''
This file is part of DopplerShift.

    DopplerShift is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DopplerShift is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DopplerShift.  If not, see <http://www.gnu.org/licenses/>.
'''
from twisted.protocols.basic import LineReceiver
import json
import logging
logger = logging.getLogger(__name__)

class CollectorShellProtocol(LineReceiver):
    def lineReceived(self, line):
        obj = json.loads(line)
        logger.debug("{lineReceived}, line: %s", line)
        if not 'command' in obj:
            self.responseSend({"error": "Unknown Command"})
        self.factory.command(obj, self.responseSend)
    def responseSend(self, obj):
        logger.debug("{responseSend}, obj: %s", obj)
        self.sendLine(json.dumps(obj))